﻿using System;
using System.Collections.Generic;

namespace EWS
{
    enum warningColor
    {
        green   = 0,
        yellow  = 1,
        orange  = 2,
        red     = 3
    };

    class WarningStep
    {
        // Konstruktor
        private WarningStep()
        {
        }

        private static bool isPulseOk(int pulse)
        {
            if (pulse > 50 && pulse < 101)
            {
                return true;
            }
            return false;
        }

        private static bool isPulseLittleDiff(int pulse)
        {
            if ((pulse >= 40 && pulse <= 50) || (pulse >= 101 && pulse <= 111))
            {
                return true;
            }
            return false;
        }

        private static bool isSysOk(int sys)
        {
            if (sys > 100 && sys < 200)
            {
                return true;
            }
            return false;
        }

        private static bool isSysLittleDiff(int sys)
        {
            if ((sys >= 80 && sys <= 100) || (sys >= 200 && sys <= 230))
            {
                return true;
            }
            return false;
        }

        private static bool isDiaOk(int dia)
        {
            if (dia > 70 && dia < 95)
            {
                return true;
            }
            return false;
        }

        private static bool isDiaLittleDiff(int dia)
        {
            if ((dia >= 60 && dia <= 70) || (dia >= 95 && dia <= 105))
            {
                return true;
            }
            return false;
        }

        private static bool isResOk(int res)
        {
            if (res > 8 && res < 25)
            {
                return true;
            }
            return false;
        }

        private static bool isResLittleDiff(int res)
        {
            if ((res >= 7 && res <= 8) || (res >= 25 && res <= 30))
            {
                return true;
            }
            return false;
        }

        private static bool isOxOk(int ox)
        {
            if (ox > 94)
            {
                return true;
            }
            return false;
        }

        private static bool isOxLittleDiff(int ox)
        {
            if ((ox >= 90) && (ox <= 94))
            {
                return true;
            }
            return false;
        }

        private static bool isTempOk(float temp)
        {
            if (temp > 35.5 && temp < 37.5)
            {
                return true;
            }
            return false;
        }

        private static bool isTempLittleDiff(float temp)
        {
            if ((temp >= 35.0 && temp <= 35.5) || (temp >= 37.5 && temp <= 38.5))
            {
                return true;
            }
            return false;
        }


        //**************************************************
        // /F0050/ Patient in Warnstufen einteilen!
        //**************************************************
        public static warningColor generateWarning(measureData myMeasureData)
        {
            int iscore = 0;

            if (isPulseLittleDiff(myMeasureData.Pulse))
            {
                iscore++;
            }
            else if (isPulseOk(myMeasureData.Pulse) == false)
            {
                iscore += 3;
            }

            if (isSysLittleDiff(myMeasureData.bpdata.Sys))
            {
                iscore++;
            }
            else if (isSysOk(myMeasureData.bpdata.Sys) == false)
            {
                iscore += 3;
            }

            if (isDiaLittleDiff(myMeasureData.bpdata.Dia))
            {
                iscore++;
            }
            else if (isDiaOk(myMeasureData.bpdata.Dia) == false)
            {
                iscore += 3;
            }

            if (isResLittleDiff(myMeasureData.ResperatoryRate))
            {
                iscore++;
            }
            else if (isResOk(myMeasureData.ResperatoryRate) == false)
            {
                iscore += 3;
            }

            if (isOxLittleDiff(myMeasureData.OxygenSaturation))
            {
                iscore++;
            }
            else if (isOxOk(myMeasureData.OxygenSaturation) == false)
            {
                iscore += 3;
            }

            if (isTempLittleDiff(myMeasureData.Temperature))
            {
                iscore++;
            }
            else if (isTempOk(myMeasureData.Temperature) == false)
            {
                iscore += 3;
            }

            // Auswertung
            switch (iscore)
            {
                case 0:
                    return warningColor.green;
                case 1:
                    return warningColor.yellow;
                case 2:
                    return warningColor.orange;
                case 3:
                default:
                    return warningColor.red;
            }//end switch
        }// end method 
    } // end class
}// end namespace